﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Resources;
using System.IO;
using System.Xml;
using System.Windows.Forms;

namespace ShopManagement.Common
{
    public class Utility
    {
        #region Attributes
        private ResourceManager _myResource;
        private static XmlDocument _settingFile;
        #endregion

        #region Methods

        public Utility()
        {
            _settingFile = new XmlDocument();
            _settingFile.LoadXml(Constants.SettingFileName);
        }

        public static string GetSetting(string elementName)
        {
            XmlNode tmp = _settingFile.SelectSingleNode(Constants.RootNode);
            return tmp[elementName].InnerText;
        }

        public static string GenerateAccessConnectionString(string passWord)
        {
            return String.Format(Constants.AccessConnectionString, Constants.AccessProvider,
                                 Directory.GetCurrentDirectory() + Constants.CommonLetter.SlashString +
                                 Constants.AccessFileName, passWord);
        }

        public static string GetPathToCurrentFolder()
        {
            return AppDomain.CurrentDomain.BaseDirectory;
        }

        public static void TransformProductTable(ref DataGridView myView, int role)
        {
            
            myView.Columns["ID"].Visible = false;
            myView.Columns["Type"].Visible = false;
            myView.Columns["ProductCode"].HeaderText = "Mã Sản Phẩm";
            myView.Columns["ProductName"].HeaderText = "Tên Sản Phẩm";
            myView.Columns["Price"].HeaderText = "Giá Bán";
            myView.Columns["NetValue"].HeaderText = "Giá Nhập";
            myView.Columns["Image"].HeaderText = "Hình Mẫu Sản Phẩm";
            myView.Columns["Quantity"].HeaderText = "Số Lượng Nhập";
            myView.Columns["Sold"].HeaderText = "Số Lượng Đã Bán";
            myView.Columns["Detail"].HeaderText = "Thông Tin Chi Tiết";
            myView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
            myView.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            myView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            if(role == Constants.RoleUser)
            {
                myView.Columns["NetValue"].Visible = false;
            }
        }

        public static void TransformOrderTable(ref DataGridView myView)
        {
            myView.Columns["ID"].HeaderText = "Đơn Hàng Số";
            myView.Columns["CustomerName"].HeaderText = "Khách Hàng";
            myView.Columns["ProductId"].HeaderText = "Mã Sản Phẩm";
            myView.Columns["Quantity"].HeaderText = "Số Lượng";
            myView.Columns["StartDate"].HeaderText = "Ngày Đặt Hàng";
            myView.Columns["Status"].HeaderText = "Trạng Thái";
            myView.Columns["Detail"].HeaderText = "Chi Tiết";
            myView.Columns["Profit"].Visible = false;
            myView.Columns["EndDate"].HeaderText = "Ngày Kết Thúc";
            myView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            myView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
            myView.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
        }

        #endregion Methods
    }
}
